//关于layout组件的配置仓库
import { defineStore } from "pinia";
import {
  getCategory1List,
  getCategory2List,
  getCategory3List,
} from "@/api/product/attr";
import { CategoryListResp } from "@/api/product/attr/type";
import type { CategoryState } from "./types/type";

let categoryConfigStore = defineStore("categoryConfig", {
  state: (): CategoryState => {
    return {
      category1List: [],
      category2List: [],
      category3List: [],
      category1Id: undefined,
      category2Id: undefined,
      category3Id: undefined,
      isDisabled: false,
    };
  },
  actions: {
    async getCategory1List() {
      let result: CategoryListResp = await getCategory1List();
      if (result.code === 200) {
        this.category1List = result.data;
      }
    },
    async getCategory2List() {
      let result: CategoryListResp = await getCategory2List(this.category1Id);
      if (result.code === 200) {
        this.category2List = result.data;
      }
    },
    async getCategory3List() {
      let result: CategoryListResp = await getCategory3List(this.category2Id);
      if (result.code === 200) {
        this.category3List = result.data;
      }
    },

    clearCategory2And3() {
      this.category2Id = undefined;
      this.category3Id = undefined;
      this.category3List = [];
    },
    clearCategory3() {
      this.category3Id = undefined;
    },
  },
});
export default categoryConfigStore;
